package com.xiaoyu.lanling.feature.friend.viewholder

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import com.xiaoyu.base.utils.extensions.getViewTag
import com.xiaoyu.base.utils.extensions.setOnClickDebounceListener
import com.xiaoyu.base.utils.extensions.setViewTag
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.feature.friend.model.FriendItem
import com.xiaoyu.lanling.feature.user.data.UserInfoData

class FansViewHolder : FriendViewHolder() {

    companion object {
        val sOnSubscribeButtonClickListener = View.OnClickListener {
            val item = it.getViewTag<FriendItem>() ?: return@OnClickListener
            UserInfoData.subscribeUser(Any(), item.user.uid, true)
        }
    }

    private var mButton: Button? = null

    override fun createView(layoutInflater: LayoutInflater, parent: ViewGroup): View? {
        val view = super.createView(layoutInflater, parent)
        mButton = view?.findViewById(R.id.subscribe_button)
        mButton?.setOnClickDebounceListener(sOnSubscribeButtonClickListener)
        return view
    }

    override fun getLayoutRes(): Int {
        return R.layout.item_fans
    }

    override fun showData(position: Int, itemData: FriendItem) {
        super.showData(position, itemData)
        mButton?.setViewTag(itemData)
    }
}